﻿using HKB.Common;
using HKB.Web.Admin;
using HKB.Web.DataHelper;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Admin_Admin_Specifications : Admin, IRequiresSessionState
{
    private int _returnDataCountForEach = 12;
    private int _AllCount = -1;
    private Shop_SepcBll _sepc;
    protected int ReturnDataCountForEach
    {
        get
        {
            return this._returnDataCountForEach;
        }
        set
        {
            this._returnDataCountForEach = value;
        }
    }
    protected int AllCount
    {
        get
        {
            int allCount;
            if (this._AllCount != -1)
            {
                allCount = this._AllCount;
            }
            else
            {
                DataTable dataTable = this.conn.GetDataTable("select count(*) as AllCount  from HLShop_spec  ");
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    this._AllCount = Convert.ToInt32(dataTable.Rows[0]["AllCount"]);
                }
                allCount = this._AllCount;
            }
            return allCount;
        }
        set
        {
            this._AllCount = value;
        }
    }
    public Shop_SepcBll Sepc
    {
        get
        {
            Shop_SepcBll sepc;
            if (this._sepc == null)
            {
                this._sepc = new Shop_SepcBll();
                sepc = this._sepc;
            }
            else
            {
                sepc = this._sepc;
            }
            return sepc;
        }
        set
        {
            this._sepc = value;
        }
    }
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            this.Bind();
            this.GetPageLink();
        }
    }
    public void Bind()
    {
        int pageIndex = this.ValidateQueString();
        this.Repeater1.DataSource = this.Sepc.GetSepcAll(pageIndex, this.ReturnDataCountForEach);
        this.Repeater1.DataBind();
    }
    private string GetPage(int yushu, int page, int last, int allpage)
    {
        string text = base.Request.Url.ToString().ToLower();
        int begin = text.LastIndexOf("page=");
        int deletePoint = this.GetDeletePoint(begin, text);
        string text2 = "";
        for (int i = 1; i <= yushu; i++)
        {
            if (page == last && page != allpage && page % 10 != 0)
            {
                object obj = text2;
                text2 = string.Concat(new object[]
				{
					obj,
					"<li><a  href='?page=",
					last + i,
					"'><span class='",
					(page == last + i - 1) ? "currentpage" : "",
					"'>",
					last + i,
					"</span></a></li>"
				});
            }
            else
            {
                if (page == last && page == allpage)
                {
                    last -= 10;
                    object obj = text2;
                    text2 = string.Concat(new object[]
					{
						obj,
						"<li><a  href='?page=",
						last + i,
						"'><span class='",
						(page == last + i) ? "currentpage" : "",
						"'>",
						last + i,
						"</span></a></li>"
					});
                }
                else
                {
                    if (page == last && page != allpage && page % 10 == 0)
                    {
                        last -= 10;
                        object obj = text2;
                        text2 = string.Concat(new object[]
						{
							obj,
							"<li><a  href='?page=",
							last + i,
							"'><span class='",
							(page == last + i - 1) ? "currentpage" : "",
							"'>",
							last + i,
							"</span></a></li>"
						});
                    }
                    else
                    {
                        object obj = text2;
                        text2 = string.Concat(new object[]
						{
							obj,
							"<li><a  href='?page=",
							last + i,
							"'><span class='",
							(page == last + i) ? "currentpage" : "",
							"'>",
							last + i,
							"</span></a></li>"
						});
                    }
                }
            }
        }
        return text2;
    }
    private void GetPageLink()
    {
        string text = base.Request.Url.ToString().ToLower();
        int begin = text.LastIndexOf("page=");
        int deletePoint = this.GetDeletePoint(begin, text);
        int num = this.ValidateQueString();
        int num2 = (this.AllCount + this.ReturnDataCountForEach - 1) / this.ReturnDataCountForEach;
        if (num2 == 0)
        {
            this.ltrPage.Text = "<li><a  href='javascript:;'><span>上一页</span></a></li><li><a  href='javascript:'><span>下一页</span></a></li>";
        }
        else
        {
            if (num <= num2 && num > 0)
            {
                string text2 = "";
                text2 += ((num == 1) ? "<li><a  href='javascript:;'><span>上一页</span></a></li>" : ("<li><a  href='?page=" + (num - 1) + "'><span>上一页</span></a></li>"));
                if (num > 0 && num <= 10)
                {
                    int yushu = (num2 / 10 > 0) ? 10 : num2;
                    text2 += this.GetPage(yushu, num, 0, num2);
                }
                else
                {
                    if (num > 10 && num <= 10 * (num2 / 10))
                    {
                        int last = 10 * (num / 10);
                        text2 += this.GetPage(10, num, last, num2);
                    }
                    else
                    {
                        if (num > 10 * (num2 / 10) && num <= num2)
                        {
                            int yushu = num2 % 10;
                            int last = 10 * (num2 / 10);
                            text2 += this.GetPage(yushu, num, last, num2);
                        }
                    }
                }
                if (num2 == num)
                {
                    text2 += "<li><a  href='javascript:'><span>下一页</span></a></li>";
                }
                else
                {
                    object obj = text2;
                    text2 = string.Concat(new object[]
					{
						obj,
						"<li><a  href='?page=",
						num + 1,
						"'><span>下一页</span></a></li>"
					});
                }
                this.ltrPage.Text = text2;
            }
        }
    }
    private int GetDeletePoint(int begin, string url)
    {
        int result = begin;
        if (begin > 0)
        {
            result = begin + 1;
            for (int i = begin + 1; i < url.Length; i++)
            {
                if (url[i] == '&')
                {
                    result = i;
                }
            }
        }
        return result;
    }
    private int ValidateQueString()
    {
        string text = base.Request.QueryString["page"];
        int num = 1;
        int result;
        if (!string.IsNullOrEmpty(text))
        {
            if (!int.TryParse(text, out num))
            {
                result = 1;
            }
            else
            {
                result = num;
            }
        }
        else
        {
            result = 1;
        }
        return result;
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            bool deleteSepc = this.Sepc.GetDeleteSepc(Convert.ToInt32(e.CommandArgument));
            if (deleteSepc)
            {
                this.WriteErrMsg("", Language.GetAdminMsg("UserGroup/GrouNumErr"), "Admin_Specifications.aspx");
            }
        }
    }
    protected void linkDelete_Click(object sender, EventArgs e)
    {
        bool flag = false;
        foreach (RepeaterItem repeaterItem in this.Repeater1.Items)
        {
            HtmlInputCheckBox htmlInputCheckBox = (HtmlInputCheckBox)repeaterItem.FindControl("itemsbox");
            if (htmlInputCheckBox.Checked)
            {
                flag = this.Sepc.GetDeleteSepc(Convert.ToInt32(htmlInputCheckBox.Value));
            }
        }
        if (flag)
        {
            this.WriteErrMsg("", Language.GetAdminMsg("UserGroup/GrouNumErr"), "Admin_Specifications.aspx");
        }
    }
}
